package com.gxa.check.controller;

import com.gxa.log.cofig.OperateLogConfig;
import dto.ResultDTO;
import com.gxa.check.service.ExamineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 审核表(Examine)表控制层
 *
 * @author makejava
 * @since 2021-05-11 15:23:48
 */
@RestController
@RequestMapping("check")
@Api(tags = "订单审核相关的接口")
public class ExamineController {
    /**
     * 服务对象
     */
    @Resource
    private ExamineService examineService;

    /**
     * 根据订单ID创建审核表
     * @param macOrderId
     * @return
     */
    @PostMapping("add/macOrder")
    public ResultDTO addMac(@RequestParam Integer macOrderId){
        return examineService.addMac(macOrderId);
    }

    @ApiOperation(value = "机械单的同意操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "macOrderId", value = "机械订单的ID", required = true),
            @ApiImplicitParam(name = "memberId", value = "审核人ID", required = true)
    })
    @PostMapping("pass/macOrder")
    public ResultDTO possMacOrder(@RequestParam Integer macOrderId, Integer memberId){
        return examineService.possMacOrder(macOrderId, memberId);
    }

    @ApiOperation(value = "机械单的拒绝操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "macOrderId", value = "机械订单的ID", required = true),
            @ApiImplicitParam(name = "refuseMsg", value = "拒绝理由", required = true),
            @ApiImplicitParam(name = "memberId", value = "审核人ID", required = true)
    })
    @PostMapping("refuse/macOrder")
    public ResultDTO refuseMacOrder(@RequestParam Integer macOrderId, @RequestParam String refuseMsg, @RequestParam Integer memberId){
        return examineService.refuseMacOrder(macOrderId, refuseMsg, memberId);
    }

    @ApiOperation(value = "人工单的同意操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "artOrderId", value = "机械订单的ID", required = true),
            @ApiImplicitParam(name = "memberId", value = "审批人ID", required = true)
    })
    @PostMapping("pass/artOrder")
    public ResultDTO possArtOrder(@RequestParam Integer artOrderId, @RequestParam Integer memberId){
        return examineService.possArtOrder(artOrderId, memberId);
    }

    @ApiOperation(value = "人工单的拒绝操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "artOrderId", value = "机械订单的ID", required = true),
            @ApiImplicitParam(name = "memberId", value = "审批人ID", required = true),
            @ApiImplicitParam(name = "refuseMsg", value = "拒绝理由", required = true)
    })
    @PostMapping("refuse/artOrder")
    public ResultDTO refuseArtOrder(@RequestParam Integer artOrderId, @RequestParam Integer memberId, @RequestParam String refuseMsg){
        return examineService.refuseArtOrder(artOrderId, memberId, refuseMsg);
    }

    /**
     * 查询机械单的审核人
     * @param macOrderId
     * @return
     */
    @PostMapping("macOrder/member")
    public ResultDTO exaMacOrderMember(@RequestParam Integer macOrderId){
        return examineService.exaMacOrderMember(macOrderId);
    }

    /**
     * 查询人工单的审核人
     * @return
     */
    @PostMapping("artOrder/member")
    public ResultDTO exaArtOrderMember(@RequestParam Integer artOrderId){
        return examineService.exaArtOrderMember(artOrderId);
    }

    @ApiOperation(value = "根据订单id和订单类型查询审核结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true),
            @ApiImplicitParam(name = "type", value = "订单的类型", required = true)
    })
    @PostMapping("/order")
    public ResultDTO checkOrder(@RequestParam Integer orderId, @RequestParam Integer type){
        return examineService.checkOrder(orderId, type);
    }


    @PostMapping("find/all/dept")
    @OperateLogConfig(OperateModule = "审核服务",OperateType = "查询",OperateDesc = "查询所有的部门")
    @ApiOperation(value = "查询所有的部门")
    public ResultDTO findALlDept(){
        return examineService.findAllDept();
    }
}
